// hyb_yl/czhuanjiasubpages/pages/questends/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oneinfo: [{
        text1: '医生姓名',
        text2: '李秀清'
      },
      {
        text1: '订单名称',
        text2: '电话问诊'
      },
      {
        text1: '订单编号',
        text2: '6379287611'
      },
      {
        text1: '患者姓名',
        text2: '啊啊啊'
      }
    ],
    all_num: 2,
    datalist: [],
    sickimg: [], //患处照片
    medimg: [], //药物照片
    sickhisty: [],
    allergy: [],
    hospatil: [], //就诊过的医院
    dochelp: '',
    sicktel: '', //病人电话
    userInfo: {},
    //体检报告
    datatime: [], //体检日期
    textvalue: [],
    issmoke: [],
    liangsmoke: [],
    smoking: [],
    jiesmok: [],
    iswine: [],
    classwine: [],
    liangwine: [],
    jiewine: [],
    isactive: [],
    datactive: [],
    timeactive: [],
    classactive: [],
    img2: [],
    disableJoin: false,
  },
  //跳转支付页面
  onGotUserInfo: function(e) {
    //支付
    var that = this
    var zid = that.data.zid
    var uniacid = app.siteInfo.uniacid;
    var bingzs = that.data.bingzs
    var money = that.data.money
    var oid = that.data.oid
    var order = that.data.order
    console.log(order)
    var bl_id = that.data.bl_id
    //只要咨询就关注医生
    app.util.request({
      'url': 'entry/wxapp/Zhuanjia.ifguanzhu',
      data: {
        zid: zid,
        openid: wx.getStorageSync('openid'),
        cerated_type: 0
      },
      success: function(res) {
        console.log(res)
        if (res.data !== 1) {
          //添加关注
          app.util.request({
            'url': 'entry/wxapp/Zhuanjia.changelove',
            data: {
              zid: zid,
              openid: wx.getStorageSync('openid'),
              cerated_type: 0
            },
            success: function(res) {
              console.log(res)
            }
          })
        }
      }
    })

    wx.showModal({
      content: '是否支付',
      success: function(res) {
        if (res.confirm) {
          app.util.request({
            'url': that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Pay&m=hyb_yl',
            header: {
              "Content-Type": "application/xml"
            },
            method: "GET",
            data: {
              openid: wx.getStorageSync('openid'),
              z_tw_money: money
            },
            success: function(res) {
              console.log(res);
              wx.requestPayment({
                'timeStamp': res.data.timeStamp,
                'nonceStr': res.data.nonceStr, //字符串随机数
                'package': res.data.package,
                'signType': res.data.signType,
                'paySign': res.data.paySign,
                success: function(res) {
                  console.log(res)
                  //通知医生
                  app.util.request({
                    'url': 'entry/wxapp/Wxmoban.doctemp',
                    data: {
                      openid: wx.getStorageSync('openid'),
                      zid: zid,
                      bingzs: bingzs,
                      name: that.data.name,
                      oid: oid,
                      bl_id: bl_id,
                      order: order//改变订单状态
                    },
                    success: function(res) {
                      console.log(res)
                    }
                  })
                  var docroom = that.data.docroom
                  //加入数据库在进入房间
                  wx.setStorageSync('docroom', docroom)
                  let userInfo = e.detail.userInfo || {};
                  wx.setStorage({
                    key: 'userInfo',
                    data: userInfo,
                  })
                  var key = that.data.keywords
                  that.onJoin(userInfo);
                }
              })
            }
          })
        } else {
          //跳转订单详情页面
          wx.reLaunch({
            url: '/hyb_yl/mysubpages/pages/my_dingdan1/my_dingdan1',
          })
        }
      }
    })
  },
  checkJoinLock: function() {
    return !(this.lock || false);
  },

  lockJoin: function() {
    this.lock = true;
  },

  unlockJoin: function() {
    this.lock = false;
  },
  onJoin: function(userInfo) {
    userInfo = userInfo || {};
    let value = this.channel || "123";
    let uid = this.uid;
    if (!value) {
      wx.showToast({
        title: '请提供一个有效的房间名',
        icon: 'none',
        duration: 2000
      })
    } else {
      if (this.checkJoinLock()) {
        this.lockJoin();
        let role = "audience";
        role = "broadcaster";
        wx.navigateTo({
          url: `../meeting/meeting?channel=${value}&uid=${uid}&role=${role}`
        });
      }
    }
  },
  //下一页
  nextpage: function() {
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/telserev/index',
    })
  },
  nextpage2: function() {
    wx.reLaunch({
      url: '/hyb_yl/czhuanjiasubpages/pages/healreport/index',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    // console.log(options.num)
    let zid = options.zid
    var keywords = options.keywords
    var name = options.name
    var bgc = wx.getStorageSync('color')
    var bingzs = options.bingzs
    var money = options.money
    var bl_id = options.bl_id
    var oid = options.oid
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.setData({
      all_num: options.num,
      bgc: bgc,
      zid: zid,
      j_id: options.j_id,
      keywords: keywords,
      name: name,
      bingzs: bingzs,
      money: money,
      oid: oid,
      bl_id: bl_id,
    })
    if (options.num == 0) {
      wx.setNavigationBarTitle({
        title: '收银台'
      })
    } else if (options.num == 1) {
      wx.setNavigationBarTitle({
        title: '病例详情页'
      })
      let modul = wx.getStorageSync('modul')
      // console.log('题答案', modul, '电话', options.phone)
      let sickname = wx.getStorageSync('sickname')
      // console.log('疾病症状', sickname)
      let hospatil = wx.getStorageSync('hospatil')
      // console.log('就诊过的医院科室', hospatil)
      let sickimg = wx.getStorageSync('sickimg')
      // console.log('患处照片', sickimg)
      let medimg = wx.getStorageSync('medimg')
      // console.log('药物照片', medimg)
      let sickhisty = wx.getStorageSync('sickhisty')
      // console.log('病史', sickhisty)
      let allergy = wx.getStorageSync('allergy')
      // console.log('过敏', allergy)
      let dochelp = wx.getStorageSync('dochelp')

      let aaa = JSON.parse(modul)
      var datalist = this.data.datalist

      this.setData({
        hospatil: hospatil,
        datalist: aaa,
        sickimg: sickimg,
        medimg: medimg,
        sickhisty: sickhisty,
        allergy: allergy,
        hospatil: hospatil,
        dochelp: dochelp,
        sicktel: options.phone
      })
    } else if (options.num == 2) {
      wx.setNavigationBarTitle({
        title: '体检报告'
      })
      //体检报告
      let datatime = wx.getStorageSync('data') //体检日期
      console.log('体检日期', datatime)

      let textvalue = wx.getStorageSync('textvalue')
      console.log('体检机构', textvalue)

      let issmoke = wx.getStorageSync('issmoke')
      console.log('是否抽烟', issmoke)

      let liangsmoke = wx.getStorageSync('liangsmoke')
      console.log('抽烟量', liangsmoke)

      let smoking = wx.getStorageSync('smoking')
      console.log('抽烟时间', smoking)

      let jiesmok = wx.getStorageSync('jiesmok')
      console.log('戒烟时间', jiesmok)

      let iswine = wx.getStorageSync('iswine')
      console.log('是否饮酒', iswine)

      let classwine = wx.getStorageSync('classwine')
      console.log('饮酒类型', classwine)

      let liangwine = wx.getStorageSync('liangwine')
      console.log('饮酒量', liangwine)

      let jiewine = wx.getStorageSync('jiewine')
      console.log('戒酒时间', jiewine)

      let isactive = wx.getStorageSync('isactive')
      console.log('是否锻炼', isactive)

      let datactive = wx.getStorageSync('datactive')
      console.log('锻炼情况', datactive)

      let timeactive = wx.getStorageSync('timeactive')
      console.log('锻炼时长', timeactive)

      let classactive = wx.getStorageSync('classactive')
      console.log('锻炼类型', classactive)

      let img2 = wx.getStorageSync('img2')
      console.log('体检图片', img2)

      this.setData({
        datatime,
        textvalue,
        issmoke,
        liangsmoke,
        smoking,
        jiesmok,
        iswine,
        classwine,
        liangwine,
        jiewine,
        isactive,
        datactive,
        timeactive,
        classactive,
        img2
      })
    } else if (options.num == 3) {
      //希望得到的帮助
      var help = wx.getStorageSync('help')
      var help_h = help.join('　');
      var str = []
      let jbname = wx.getStorageSync('jbname')
      for (var i = 0; i < jbname.length; ++i) {
        str.push(jbname[i].value)
      }
      var img_arr = wx.getStorageSync('img_arr')
      var str1 = str.join('　');
      let selectbc = wx.getStorageSync('selectbc')
      let hospital = wx.getStorageSync('docinfo')
      let changes = wx.getStorageSync('changes')
      let condition = wx.getStorageSync('condition')
      if (hospital == '就诊过') {
        var docname = wx.getStorageSync('docname')
        var keshi = wx.getStorageSync('keshi')
        var docinfo = hospital + ' ' + docname + ' ' + keshi
      }
      this.setData({
        help_h: help_h,
        jbname: str1,
        selectbc: selectbc,
        docinfo: docinfo,
        changes: changes,
        condition: condition,
        img_arr: img_arr
      })
    } else if (options.num == 4) {
      var z_name = options.z_name
      var name = options.name
      var order = options.order
      var usernames = options.usernames
      var money = options.money
      this.setData({
        z_name: z_name,
        name: name,
        order: order,
        usernames: usernames,
        money: money
      })
    }
    var that = this
    app.util.request({
      'url': 'entry/wxapp/User.detail',
      data: {
        j_id: options.j_id
      },
      success: function(res) {
        console.log(res)
        that.setData({
          usernames: res.data.names
        })
      }
    })
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.docinfo',
      data: {
        zid: zid,
        key: keywords,
      },
      success: function(res) {
        that.setData({
          newmoney: res.data.data.newmoney,
          z_name: res.data.data.z_name,
        })
      }
    })
    app.util.request({
      'url': 'entry/wxapp/Hzbingli.url',
      success: function(res) {
        console.log(res)
        that.setData({
          url: res.data
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    console.log('ss')
    wx.navigateBack({
      detail: 2
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

})